#ifndef THREAD_CLASS_H
#define THREAD_CLASS_H
#include "mainwindow.h"
#include <QMainWindow>
#include "micro_define.h"


namespace Ui {
    class MainWindow;
}

class MainWindow ;

unsigned char CalculateXOR(unsigned char *pbuf,int len);
bool AES_check(unsigned char *src_data,unsigned char *encry_data);


//int Init_serial(QString u_serial);

#if 0
class ElevatorUart1Thread : public QThread {
    Q_OBJECT
    public:
    //unsigned char *p0;
    int OffsetRcv;
    unsigned char RcvBuf[BUF_SIZE];
    int uart_fd;
    int *time_out_flag;
    int received_flag_uart1;
    char uart_fisrt_receive;

    MainWindow *mw;
    QString elevator_info_uart_1;
    QTimer *timer_0;

    struct ElevatorInfoState elevator_info_state;
    QextSerialPort *port;
    ElevatorUart1Thread();
    ElevatorUart1Thread(MainWindow *mw0);
    void unpacked_func1(unsigned char *p_buf,int d_length);
    char receive_uart_data();

    virtual void run();
signals:
    void emit_update(void);

private slots:
    void update_timer(void);
    };
#endif

class ElevatorUart1ReadThread : public QThread {
    Q_OBJECT
    public:
    //unsigned char *p0;
    int OffsetRcv;
    QString com_flag;
    unsigned char RcvBuf[BUF_SIZE];
    unsigned char data_buf[BUF_SIZE];
    int uart_fd;
    int time_out_flag;
    int data_length;
    int received_flag_uart;
    char uart_fisrt_receive;

    MainWindow *mw;
    QString elevator_info_uart;
    QTimer *timer_0;

    struct ElevatorInfoState elevator_info_state;
    QextSerialPort *port;
    ElevatorUart1ReadThread();
    ElevatorUart1ReadThread(MainWindow *mw0);
    void unpacked_frame(unsigned char *p_buf, int d_length);
    virtual void run();
signals:
    void emit_update(void);

private slots:
    void dispose_data(void);
    void rec_timeout(void);
    void check_communication_stat(void);
    //void update_timer(void);
    };

class ElevatorUart2ReadThread : public QThread {
    Q_OBJECT
    public:
    //unsigned char *p0;
    int OffsetRcv;
    QString com_flag;
    unsigned char RcvBuf[BUF_SIZE];
    unsigned char data_buf[BUF_SIZE];
    int uart_fd;
    int time_out_flag;
    int data_length;
    int received_flag_uart1;
    char uart_fisrt_receive;

    MainWindow *mw;
    QString elevator_info_uart;
    QTimer *timer_0;

    struct ElevatorInfoState elevator_info_state;
    QextSerialPort *port;
    ElevatorUart2ReadThread();
    ElevatorUart2ReadThread(MainWindow *mw0);
    void unpacked_frame(unsigned char *p_buf, int d_length);
    virtual void run();
signals:
    void emit_update(void);

private slots:
    void dispose_data(void);
    void rec_timeout(void);
    void check_communication_stat(void);

    //void update_timer(void);
    };


class AES_encrypt_thread : public QThread {
    Q_OBJECT
    public:

    MainWindow *mw;
    unsigned char send_buf[64];
    unsigned char data_buf[64];
    QString elevator_info_uart_1;
    QTimer *timer_0;
    int uart_fd;

    AES_encrypt_thread();
    AES_encrypt_thread(MainWindow *mw0);

    virtual void run();
signals:
    void emit_update_info(void);
private slots:
    };

#if 0
class ElevatorUart2Thread : public QThread {
    Q_OBJECT
    public:

    int OffsetRcv;
    unsigned char RcvBuf[BUF_SIZE];
    int uart_fd;
    int *time_out_flag;
    int received_flag_uart2;
    char uart_fisrt_receive;
    QTimer *timer_0;
    MainWindow *mw;
    QString elevator_info_uart_1;
    struct ElevatorInfoState elevator_info_state;
    QextSerialPort *port;
    ElevatorUart2Thread();
    ElevatorUart2Thread(MainWindow *mw0);
    void unpacked_func2(unsigned char *p_buf,int d_length);
    char receive_uart_data(void);

    virtual void run();
signals:
    void emit_update(void);

private slots:
    void update_timer(void);
    };
#endif

class TextUartThread : public QThread {
    Q_OBJECT
    public:
    char *p0;
    char buff_in[1024];
    unsigned char buffer0[1024];
    char buff_out[16];
    QextSerialPort *port;
    QString text_uart;//uart number
    QString uart_context; // uart input context
    TextUartThread();

    virtual void run();

signals:
    void emit_update(void);
    };
#endif // THREAD_CLASS_H
